package cn.le.thread;

import java.util.concurrent.TimeUnit;
import java.util.logging.Logger;

/**
 * 轻量级同步机制,可维护可见性和进制指令重排序
 */
public class VolatileTest {

  private static boolean stop;
  static Logger log = Logger.getLogger("lavasoft");
  public static void main(String[] args) throws InterruptedException {
      Thread thread = new Thread(new Runnable() {
        @Override
        public void run() {
          int i = 0;
          while (!stop){
            /*try {
              TimeUnit.SECONDS.sleep(1);
            } catch (InterruptedException e) {
              e.printStackTrace();
            }*/
            log.info(String.valueOf(stop));
          }
        }
      });
      thread.start();
      TimeUnit.SECONDS.sleep(3);
      stop = true;
  }

}
